package com.aishua.aishuawallet.fregment;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.annotation.Nullable;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.aishua.aishuawallet.Constant;
import com.aishua.aishuawallet.R;
import com.aishua.aishuawallet.activity.BaseActivity;
import com.aishua.aishuawallet.activity.RecordActivity;
import com.aishua.aishuawallet.adapter.AccountAdapter;
import com.aishua.aishuawallet.adapter.CurrencuyAdapter;
import com.aishua.aishuawallet.adapter.RecycleViewDivider;
import com.aishua.aishuawallet.bean.ResAuthBean;
import com.aishua.aishuawallet.utils.LogUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by aishua on 2018/7/31.
 */

public class OneFregment extends BaseFragment {

    private static final String TAG = "OneFregment-";
    private Context mContext;
    private RecyclerView rl_account;
    private RecyclerView rl_currency;
    private ResAuthBean  resAuthBean;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        mContext = getContext();
        View view = View.inflate(mContext, R.layout.fregment_one, null);
        Bundle bundle = getArguments();
        resAuthBean = (ResAuthBean) bundle.getSerializable("resAuthBean");
        LogUtils.v(TAG+"resAuthBean:"+resAuthBean.toString());
//        resAuthBeanlist = new ArrayList<>();
//        ResAuthBean resAuthBean = new ResAuthBean();
//        ResAuthBean.TokenInfo tokenInfo = resAuthBean.new TokenInfo();
//
//        tokenInfo.setTokenID("11111111");
//        tokenInfo.setTokenAddr("0x05CEF8B63fFcDAA1AF8c6b41564B5041d4215b58");
//        tokenInfo.setTokenName("ETH钱包A");
//        tokenInfo.setTokenID("11111111111111111111");
//        tokenInfo.setCoinType("8000003C");
//        resAuthBean.setTokenInfo(tokenInfo);
//        resAuthBeanlist.add(resAuthBean);
        initVeiw(view);

        return view;

    }

    private void initVeiw(View view) {


        rl_account = view.findViewById(R.id.rl_account);
        rl_currency = view.findViewById(R.id.rl_currency);

        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext(),
                LinearLayoutManager.VERTICAL, false);
        rl_account.setLayoutManager(layoutManager);
//        rl_account.setItemAnimator(new DefaultItemAnimator());
//        rl_account.addItemDecoration(new RecycleViewDivider(getContext(), LinearLayoutManager.HORIZONTAL, 2, Color.GRAY));

        rl_account.setAdapter(new AccountAdapter(getActivity(), resAuthBean));

        RecyclerView.LayoutManager layoutManager1 = new LinearLayoutManager(getContext(),
                LinearLayoutManager.VERTICAL, false);
        rl_currency.setLayoutManager(layoutManager1);
        rl_currency.setItemAnimator(new DefaultItemAnimator());
//        rl_account.addItemDecoration(new RecycleViewDivider(getContext(), LinearLayoutManager.HORIZONTAL, 2, Color.GRAY));
        List list1 = new ArrayList();
        list1.add("1");

        CurrencuyAdapter currencuyAdapter = new CurrencuyAdapter(getActivity(), (ArrayList) list1);
        rl_currency.addItemDecoration(new RecycleViewDivider(getContext(), LinearLayoutManager.HORIZONTAL, 4, Color.GRAY));
        currencuyAdapter.setonRecycleViewClickListener(new CurrencuyAdapter.onRecycleViewClickListener() {
            @Override
            public void onRecycleViewClick(int position) {


               if (Constant.ISTOURIST){

                   BaseActivity baseActivity = (BaseActivity) getActivity();
                   baseActivity.touristMode();

               }else {

                   Intent intent = new Intent(mContext, RecordActivity.class);
                   intent.putExtra(Constant.ISDISPALY, true);
                   intent.putExtra("tokenaddr",resAuthBean.getTokenInfo().get(0).getTokenAddr());
                   startActivity(intent);

               }

            }
        });
        rl_currency.setAdapter(currencuyAdapter);


    }


}
